/**
 * Created by wishchen on 20118/01/31.
 */

function getC2authProject() {
    var select = document.getElementsByName("group1");
    var project = "";
    for (i = 0; i < select.length; i++) {
        if (select[i].checked == true) {
            project = select[i].value
        }
    }
    // alert(project);
    return project
}
function getC2authItems() {
    var select = document.getElementsByName("group2");
    var items = [];
    for (i = 0; i < select.length; i++) {
        if (select[i].checked == true) {
            items.push(select[i].value)
        }
    }
    // alert(items);
    return items
}

function FileUpload_jk() {
    var formData = new FormData();
    var myemail = sessionStorage.getItem('myemail');
    var file_info = $("#file_upload_jk")[0].files[0];
    if (file_info == undefined){
        alert("未选择需要上传的测试压缩文件");
        return false;
    }
    formData.append('file', file_info);
    formData.append('project', "jk");

    upf(formData);
}

function FileUpload_zed() {
    var formData = new FormData();
    var myemail = sessionStorage.getItem('myemail');
    var file_info = $("#file_upload_zed")[0].files[0];
    if (file_info == undefined){
        alert("未选择需要上传的测试压缩文件");
        return false;
    }
    formData.append('file', file_info);
    formData.append('project', "zed");

    upf(formData);
}

function FileUpload_cf() {
    var formData = new FormData();
    var myemail = sessionStorage.getItem('myemail');
    var file_info = $("#file_upload_cf")[0].files[0];
    if (file_info == undefined){
        alert("未选择需要上传的测试压缩文件");
        return false;
    }
    formData.append('file', file_info);
    formData.append('project', "cf");

    upf(formData);
}

function self_api() {
    var sessionStorage = window.sessionStorage;
    var formData = new FormData();
    var myemail = sessionStorage.getItem('myemail');
    var file_info = $("#file_upload")[0].files[0];
    if (file_info == undefined){
        alert("未选择需要上传的压缩文件");
        return false;
    }
    formData.append('file', file_info);

    upf(formData);
}
function upf(formData) {
    bootbox.confirm({
        size: "small",
        message: "是否确认上传?",
        callback: function (result) {
            if (result == true) {
                $.ajax({
                    type: "POST",
                    url: "v1/uploadFile",
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (ret) {
                        if (ret.status == "0000") {
                            alert(ret.content)
                        }else {
                            alert(ret.content)
                        }
                    },
                    error: function () {
                        alert("Error 500,请联系开发人员！");
                    }
                });
            }
        }
    })
}
function jobStatus(id, btn) {
    $.ajax({
        type: "POST",
        url: "/getjobStatus",
        data: {id: id},
        async: true,
        dataType: "json",
        success: function (ret) {
            if (ret.status == "0000") {
                $("#btnruner" + btn).removeAttr("disabled");
            }
        },
        error: function () {
            alert("Error 500,请联系开发人员！");
        }
    });
}
function saveEmail() {
    var eamil = $("#Addemail").val();
    var sessionStorage = window.sessionStorage;
    sessionStorage.setItem('myemail', eamil);
    $('#myEmail').modal('hide');
}



function run1() {
    $("#btnruner1").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        $.ajax({
            type: "POST",
            url: "/v1/userDefined_api",
            data: {jobid: 20, email: myemail, project: "jk"},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner1").attr("disabled", "disabled");
                    alert(ret['message']);
                }else{
                    alert(ret['message']);
                }
            },
            error: function () {
                alert("Error 500,请联系开发人员！");
            }
        });
        window.sessionStorage.clear();
    });
}

function run2() {
    $("#btnruner2").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        $.ajax({
            type: "POST",
            url: "/v1/userDefined_api",
            data: {jobid: 20, email: myemail, project: "zed"},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner2").attr("disabled", "disabled");
                    alert(ret['message']);
                }else{
                    alert(ret['content']);
                }
            },
            error: function () {
                alert("Error 500,请联系开发人员！");
            }
        });
        window.sessionStorage.clear();
    });
}

function run3() {
    $("#btnruner3").button('loading').queue(function () {
        var sessionStorage = window.sessionStorage;
        var myemail = sessionStorage.getItem('myemail');
        $.ajax({
            type: "POST",
            url: "/v1/userDefined_api",
            data: {jobid: 20, email: myemail, project: "cf"},
            dataType: "json",
            success: function (ret) {
                if (ret.status == "0000") {
                    $("#btnruner3").attr("disabled", "disabled");
                    alert(ret['message']);
                }else{
                    alert(ret['content']);
                }
            },
            error: function () {
                alert("Error 500,请联系开发人员！");
            }
        });
        window.sessionStorage.clear();
    });
}

function sessionClear() {
    window.sessionStorage.clear();
}

window.onload = sessionClear();
// window.onload = jobStatus(20, 1);
